//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GaussGegenbauerPolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussJacobiPolynomial.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (Double lambda) : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussGegenbauerPolynomial = NULL;
#endif
        QuantLib::Real _lambda = (QuantLib::Real)ValueHelper::Convert (lambda); //d
        _ppGaussGegenbauerPolynomial = new boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial> (new QuantLib::GaussGegenbauerPolynomial ( _lambda ));
        SetGaussJacobiPolynomial (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial>& childNative, Object^ owner) : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerPolynomial = NULL;
#endif
	_ppGaussGegenbauerPolynomial = &childNative;
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
}
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (QuantLib::GaussGegenbauerPolynomial& childNative, Object^ owner) : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerPolynomial = NULL;
#endif
	_ppGaussGegenbauerPolynomial = new boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial> (&childNative);
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
    _GaussGegenbauerPolynomialOwner = owner;
    _GaussJacobiPolynomialOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (CGaussGegenbauerPolynomial^ copy) : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerPolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussGegenbauerPolynomial = new boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial> (copy->GetShared());
        _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (PLATFORM::Type^ t) : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerPolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussGegenbauerPolynomial::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (QuantLib::Handle<QuantLib::GaussGegenbauerPolynomial>& childNative, Object^ owner)  : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
	_phGaussGegenbauerPolynomial = &childNative;
	_ppGaussGegenbauerPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial>>(childNative.currentLink());
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
    _GaussGegenbauerPolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (QuantLib::Handle<QuantLib::GaussGegenbauerPolynomial> childNative)  : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
	_phGaussGegenbauerPolynomial = &childNative;
	_ppGaussGegenbauerPolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial>>(childNative.currentLink());
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::CGaussGegenbauerPolynomial (QuantLib::GaussGegenbauerPolynomial childNative)  : CGaussJacobiPolynomial(CGaussGegenbauerPolynomial::typeid)
{
#ifdef HANDLE
	_phGaussGegenbauerPolynomial = NULL;
#endif
	_ppGaussGegenbauerPolynomial = new boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial> (new QuantLib::GaussGegenbauerPolynomial (childNative));
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussGegenbauerPolynomial));
}
#endif

Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::~CGaussGegenbauerPolynomial ()
{
    if (_ppGaussGegenbauerPolynomial != NULL)
    {
	    delete _ppGaussGegenbauerPolynomial;
        _ppGaussGegenbauerPolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::!CGaussGegenbauerPolynomial ()
{
    if (_ppGaussGegenbauerPolynomial != NULL)
    {
	    delete _ppGaussGegenbauerPolynomial;
    }
}
QuantLib::GaussGegenbauerPolynomial& Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::GetReference ()
{
    if (_ppGaussGegenbauerPolynomial == NULL) throw REFNEW NativeNullException ();
	return **_ppGaussGegenbauerPolynomial;
}
boost::shared_ptr<QuantLib::GaussGegenbauerPolynomial>& Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::GetShared ()
{
    if (_ppGaussGegenbauerPolynomial == NULL) throw REFNEW NativeNullException ();
	return *_ppGaussGegenbauerPolynomial;
}
QuantLib::GaussGegenbauerPolynomial* Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::GetPointer ()
{
    if (_ppGaussGegenbauerPolynomial == NULL) throw REFNEW NativeNullException ();
	return &**_ppGaussGegenbauerPolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussGegenbauerPolynomial>& Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::GetHandle ()
{
	if (_phGaussGegenbauerPolynomial == NULL)
	{
		_phGaussGegenbauerPolynomial = new Handle<QuantLib::GaussGegenbauerPolynomial> (*_ppGaussGegenbauerPolynomial);
	}
	return *_phGaussGegenbauerPolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial::HasNative () 
{
	return (_ppGaussGegenbauerPolynomial != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussGegenbauerPolynomial^ Cephei::QL::Math::Integrals::CGaussGegenbauerPolynomial_Factory::Create (Double lambda)
{
    return REFNEW CGaussGegenbauerPolynomial ( lambda);
}
